/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javanetworking;

import java.io.IOException;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Admin
 */
public class Responder implements Runnable{
    DatagramSocket socket = null;
    DatagramPacket packet = null;
    public Responder(DatagramSocket socket, DatagramPacket packet) {
        this.socket = socket;
        this.packet = packet;
    }
    public void run() {
        String msg="SEND FROM SERVER TO "+this.packet.getPort();
        byte[] data = msg.getBytes();
        DatagramPacket response = new DatagramPacket(data, data.length,
            packet.getAddress(), packet.getPort());
        System.out.println("Da Goi cho: "+packet.getAddress().getHostAddress()+":"+packet.getPort());
        try {
            socket.send(response);
        } catch (IOException ex) {
            Logger.getLogger(Responder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
